home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / Draw / Sources / DrawCmds.cpp < prev    next >
Encoding:
Text File  |  1996-12-16  |  25.2 KB  |  782 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                DrawCmds.cpp
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Author:                Mary Boetcher
  7. //
  8. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef DRAWCMDS_H
  15. #include "DrawCmds.h"
  16. #endif
  17.  
  18. #ifndef DRAWCONT_H
  19. #include "DrawCont.h"
  20. #endif
  21.  
  22. #ifndef DRAWPART_H
  23. #include "DrawPart.h"
  24. #endif
  25.  
  26. #ifndef DRAWSEL_H
  27. #include "DrawSel.h"
  28. #endif
  29.  
  30. #ifndef DRAWCLIP_H
  31. #include "DrawClip.h"
  32. #endif
  33.  
  34. #ifndef BASESHP_H
  35. #include "BaseShp.h"
  36. #endif
  37.  
  38. #ifndef DRAWFRM_H
  39. #include "DrawFrm.h"
  40. #endif
  41.  
  42. #ifndef GROUPSHP_H
  43. #include "GroupShp.h"
  44. #endif
  45.  
  46. #ifndef DEFINES_K
  47. #include "Defines.k"
  48. #endif
  49.  
  50. // ----- FrameWork Includes -----
  51.  
  52. #ifndef FWPRESEN_H
  53. #include "FWPresen.h"
  54. #endif
  55.  
  56. #ifndef FWMEMMGR_H
  57. #include "FWMemMgr.h"
  58. #endif
  59.  
  60. #ifndef FWSOMENV_H
  61. #include "FWSOMEnv.h"
  62. #endif
  63.  
  64. #ifndef SOM_ODShape_xh
  65. #include <Shape.xh>
  66. #endif
  67.  
  68. #ifndef FWSESION_H
  69. #include "FWSesion.h"
  70. #endif
  71.  
  72. //========================================================================================
  73. // RunTime Info
  74. //========================================================================================
  75.  
  76. #ifdef FW_BUILD_MAC
  77. #pragma segment odfdrawcommand
  78. #endif
  79.  
  80. FW_DEFINE_AUTO(CDrawShapeCommand)
  81. FW_DEFINE_AUTO(CResizeShapeCommand)
  82. FW_DEFINE_AUTO(CChangeShapeCommand)
  83. FW_DEFINE_AUTO(CChangeColorCommand)
  84. FW_DEFINE_AUTO(CChangePatternCommand)
  85. FW_DEFINE_AUTO(CChangeRenderVerbCommand)
  86. FW_DEFINE_AUTO(CChangePenSizeCommand)
  87.     
  88. //========================================================================================
  89. // CDrawShapeCommand
  90. //========================================================================================
  91.  
  92. //----------------------------------------------------------------------------------------
  93. //    CDrawShapeCommand constructor
  94. //----------------------------------------------------------------------------------------
  95. CDrawShapeCommand::CDrawShapeCommand(Environment* ev,
  96.                                     CDrawPart* part, 
  97.                                     FW_CFrame* frame,
  98.                                      CDrawSelection* selection,
  99.                                      CBaseShape* newShape) :
  100. #if defined(FW_BUILD_WIN) && FW_OPENDOC_VERSION == FW_OPENDOC_DR1
  101.     FW_CCommand(ev, cDrawShapeCommand, frame, FW_kCantUndo),
  102. #else
  103.     FW_CCommand(ev, cDrawShapeCommand, frame, FW_kCanUndo),
  104. #endif
  105.         fDrawPart(part),
  106.         fDrawSelection(selection),
  107.         fNewContent(NULL)
  108. {
  109.     SetMenuStringsFromResource(ev, kDrawUndoStrings, kUndoDrawingMsg, kRedoDrawingMsg);
  110.  
  111.     fNewContent = FW_NEW(CDrawContent, (ev, part, fDrawSelection->GetDragRect()));
  112.     fNewContent->AddShape(ev, newShape);
  113.  
  114.     FW_END_CONSTRUCTOR    
  115. }
  116.  
  117. //----------------------------------------------------------------------------------------
  118. //    CDrawShapeCommand destructor
  119. //----------------------------------------------------------------------------------------
  120. CDrawShapeCommand::~CDrawShapeCommand()
  121. {
  122.     FW_START_DESTRUCTOR
  123.     delete fNewContent;
  124. }
  125.  
  126. //----------------------------------------------------------------------------------------
  127. //    CDrawShapeCommand::FreeRedoState
  128. //----------------------------------------------------------------------------------------
  129.  
  130.  
  131. //----------------------------------------------------------------------------------------
  132. //    CDrawShapeCommand::DoIt
  133. //----------------------------------------------------------------------------------------
  134. void CDrawShapeCommand::DoIt(Environment* ev)    // Override
  135. {
  136.     if (this->IsOKtoEdit(ev))
  137.     {
  138.         fDrawPart->AddShapeToPart(ev, fNewContent->GetFirstShape());
  139.     //    fDrawSelection->SelectContent(ev, fNewContent);
  140.     }
  141.     else
  142.     {
  143.         this->SetCausesChange(ev, false);
  144.         this->SetCanUndo(ev, false);
  145.     }
  146. }
  147.  
  148. //----------------------------------------------------------------------------------------
  149. //    CDrawShapeCommand::UndoIt
  150. //----------------------------------------------------------------------------------------
  151. void CDrawShapeCommand::UndoIt(Environment* ev)    // Override
  152. {
  153.     // Unselect everything
  154.     fDrawSelection->CloseSelection(ev);
  155.  
  156.     // Remove the shape from the part
  157.     fDrawPart->RemoveShapeFromPart(ev, fNewContent->GetFirstShape());
  158.     fNewContent->RedrawShapes(ev);    // force redraw
  159. }
  160.  
  161. //----------------------------------------------------------------------------------------
  162. //    CDrawShapeCommand::RedoIt
  163. //----------------------------------------------------------------------------------------
  164. void CDrawShapeCommand::RedoIt(Environment* ev)    // Override
  165. {
  166.     // Add the shape back into the part
  167.     fDrawPart->AddShapeToPart(ev, fNewContent->GetFirstShape());
  168.     fNewContent->RedrawShapes(ev);    // force redraw
  169.  
  170.     // Select the shape
  171.     fDrawSelection->SelectContent(ev, fNewContent);
  172. }
  173.  
  174. //========================================================================================
  175. // CResizeShapeCommand
  176. //========================================================================================
  177.  
  178. //----------------------------------------------------------------------------------------
  179. //    CResizeShapeCommand constructor
  180. //----------------------------------------------------------------------------------------
  181. CResizeShapeCommand::CResizeShapeCommand(Environment* ev, 
  182.                                         CDrawPart* part, 
  183.                                          FW_CFrame* frame,
  184.                                          CDrawSelection* selection,
  185.                                          const FW_CRect& srcRect,
  186.                                          const FW_CRect& dstRect) :
  187. #if defined(FW_BUILD_WIN) && FW_OPENDOC_VERSION == FW_OPENDOC_DR1
  188.     FW_CCommand(ev, cResizeCommand, frame, FW_kCantUndo),
  189. #else
  190.     FW_CCommand(ev, cResizeCommand, frame, FW_kCanUndo),
  191. #endif
  192.         fDrawPart(part),
  193.         fDrawSelection(selection),
  194.         fSourceRect(srcRect),
  195.         fDestRect(dstRect),
  196.         fUpdateShape(NULL),
  197.         fChangedContent(NULL)
  198. {
  199.     SetMenuStringsFromResource(ev, kDrawUndoStrings, kUndoResizeMsg, kRedoResizeMsg);
  200.     FW_END_CONSTRUCTOR    
  201. }
  202.  
  203. //----------------------------------------------------------------------------------------
  204. //    CResizeShapeCommand destructor
  205. //----------------------------------------------------------------------------------------
  206. CResizeShapeCommand::~CResizeShapeCommand()
  207. {
  208.     FW_START_DESTRUCTOR
  209.     delete fChangedContent;
  210.     
  211.     if (fUpdateShape)
  212.     {
  213.         FW_SOMEnvironment ev;
  214.         fUpdateShape->Release(ev);
  215.     }
  216.     fUpdateShape = NULL;
  217. }
  218.  
  219. //----------------------------------------------------------------------------------------
  220. //    CResizeShapeCommand::DoIt
  221. //----------------------------------------------------------------------------------------
  222. void CResizeShapeCommand::DoIt(Environment* ev)    // Override
  223. {
  224.     if (!this->IsOKtoEdit(ev))
  225.     {
  226.         SetCanUndo(ev, false);
  227.         SetCausesChange(ev, false);
  228.         return;
  229.     }
  230.  
  231.     // Copy selected shape pointers to our content object
  232.     FW_ASSERT(fChangedContent == NULL);
  233.     fChangedContent = FW_NEW(CDrawContent, (ev, fDrawPart, fDrawSelection->GetDrawContent(ev)));
  234.  
  235.     FW_ASSERT(fUpdateShape == NULL);
  236.     fUpdateShape = fChangedContent->CalcUpdateShape(ev);
  237.  
  238.     this->MapShapes(ev, fSourceRect, fDestRect);
  239.  
  240.     {
  241.         FW_CAcquiredODShape tempShape = fChangedContent->CalcUpdateShape(ev);
  242.         fUpdateShape->Union(ev, tempShape);
  243.     }
  244.     
  245.     this->Redraw(ev, kODDone);
  246. }
  247.  
  248. //----------------------------------------------------------------------------------------
  249. //    CResizeShapeCommand::UndoIt
  250. //----------------------------------------------------------------------------------------
  251. void CResizeShapeCommand::UndoIt(Environment* ev)    // Override
  252. {
  253.     this->MapShapes(ev, fDestRect, fSourceRect);
  254.     this->Redraw(ev, kODUndone);
  255. }
  256.  
  257. //----------------------------------------------------------------------------------------
  258. //    CResizeShapeCommand::RedoIt
  259. //----------------------------------------------------------------------------------------
  260. void CResizeShapeCommand::RedoIt(Environment* ev)    // Override
  261. {
  262.     this->MapShapes(ev, fSourceRect, fDestRect);
  263.     this->Redraw(ev, kODRedone);
  264. }
  265.  
  266. //----------------------------------------------------------------------------------------
  267. //    CResizeShapeCommand::MapShapes
  268. //----------------------------------------------------------------------------------------
  269. void CResizeShapeCommand::MapShapes(Environment* ev, const FW_CRect& srcRect, const FW_CRect& dstRect)
  270. {
  271.     //--- Resize each shape ---
  272.     CDrawContentShapeIterator it(fChangedContent);
  273.     for (CBaseShape* shape = it.First(); it.IsNotComplete(); shape = it.Next())
  274.     {
  275.         shape->MapShape(ev, srcRect, dstRect);
  276.     }
  277. }
  278.  
  279. //----------------------------------------------------------------------------------------
  280. //    CResizeShapeCommand::Redraw
  281. //----------------------------------------------------------------------------------------
  282. void CResizeShapeCommand::Redraw(Environment* ev, ODDoneState doneState)
  283. {
  284. FW_UNUSED(doneState);
  285.     FW_CPresentation* presentation = fDrawPart->GetMainPresentation();
  286.     presentation->Invalidate(ev, fUpdateShape);
  287.     
  288.     CDrawFacetClipper facetClipper(fDrawPart);
  289.     facetClipper.Clip(ev, presentation, fUpdateShape);
  290.  
  291.     // Select the resized shapes
  292.     fDrawSelection->SelectContent(ev, fChangedContent);
  293. }
  294.  
  295. //----------------------------------------------------------------------------------------
  296. //    CResizeShapeCommand::IsOKtoEdit
  297. //----------------------------------------------------------------------------------------
  298. FW_Boolean CResizeShapeCommand::IsOKtoEdit(Environment* ev) 
  299. {
  300.     FW_Boolean result = FW_CCommand::IsOKtoEdit(ev);
  301.     
  302.     if (result)
  303.         result = fDrawSelection->CanEditSelection(ev, GetContextFrame(ev));
  304.     
  305.     return result;
  306. }
  307.  
  308. //----------------------------------------------------------------------------------------
  309. //    CResizeShapeCommand::PropagateChanges
  310. //----------------------------------------------------------------------------------------
  311. void CResizeShapeCommand::PropagateChanges(Environment* ev, ODUpdateID id )
  312. {
  313.     if (id == kODUnknownUpdate)
  314.         id = FW_CSession::UniqueUpdateID(ev);
  315.         
  316.     fDrawSelection->SelectionChanged(ev, id);
  317.     FW_CCommand::PropagateChanges(ev, id);
  318. }
  319.  
  320.  
  321.  
  322. //========================================================================================
  323. // CChangeShapeCommand
  324. //========================================================================================
  325.  
  326. //----------------------------------------------------------------------------------------
  327. //    CChangeShapeCommand constructor
  328. //----------------------------------------------------------------------------------------
  329.  
  330. CChangeShapeCommand::CChangeShapeCommand(Environment* ev,
  331.                                         ODCommandID id,
  332.                                          CDrawPart* part, 
  333.                                          FW_CFrame* frame,
  334.                                          CDrawSelection* selection) :
  335.     FW_CCommand(ev, id, frame, FW_kCanUndo),
  336.     fDrawPart(part),
  337.     fDrawSelection(selection),
  338.     fChangedContent(NULL)
  339. {
  340.     FW_END_CONSTRUCTOR    
  341. }
  342.  
  343. //----------------------------------------------------------------------------------------
  344. //    CChangeShapeCommand destructor
  345. //----------------------------------------------------------------------------------------
  346.  
  347. CChangeShapeCommand::~CChangeShapeCommand()
  348. {
  349.     FW_START_DESTRUCTOR
  350.     delete fChangedContent;
  351. }
  352.  
  353. //----------------------------------------------------------------------------------------
  354. //    CChangeShapeCommand::DoIt
  355. //----------------------------------------------------------------------------------------
  356.  
  357. void CChangeShapeCommand::DoIt(Environment* ev)            // Override
  358. {
  359.     if (!this->IsOKtoEdit(ev))
  360.     {
  361.         SetCanUndo(ev, false);
  362.         SetCausesChange(ev, false);
  363.         return;
  364.     }
  365.  
  366.     // Copy selected shape pointers to our content object
  367.     FW_ASSERT(fChangedContent == NULL);
  368.     fChangedContent = FW_NEW(CDrawContent, (ev, fDrawPart, fDrawSelection->GetDrawContent(ev)));
  369.  
  370.     this->SaveUndoState(ev);    // Save command-specific data
  371.     this->DoChange(ev);            // perform command-specific tasks
  372.  
  373.     this->UpdateDisplay(ev);
  374. }
  375.  
  376. //----------------------------------------------------------------------------------------
  377. //    CChangeShapeCommand::UndoIt
  378. //----------------------------------------------------------------------------------------
  379.  
  380. void CChangeShapeCommand::UndoIt(Environment* ev)            // Override
  381. {
  382.     // Iterate through the shape list, undoing each change
  383.     CAllShapeIterator it(fChangedContent);
  384.     unsigned long index = 0;
  385.     for (CBaseShape* shape = it.First(); it.IsNotComplete(); shape = it.Next())
  386.     {
  387.         this->UndoShape(ev, shape, index);
  388.         index++;
  389.     }
  390.  
  391.     this->UpdateDisplay(ev);
  392. }
  393.  
  394. //----------------------------------------------------------------------------------------
  395. //    CChangeShapeCommand::RedoIt
  396. //----------------------------------------------------------------------------------------
  397.  
  398. void CChangeShapeCommand::RedoIt(Environment* ev)            // Override
  399. {
  400.     this->DoChange(ev);
  401.     this->UpdateDisplay(ev);
  402. }
  403.  
  404. //----------------------------------------------------------------------------------------
  405. //    CChangeShapeCommand::UpdateDisplay
  406. //----------------------------------------------------------------------------------------
  407.  
  408. void CChangeShapeCommand::UpdateDisplay(Environment* ev)
  409. {
  410.     // Redraw the changed shapes
  411.     fChangedContent->RedrawShapes(ev);
  412.  
  413.     // Select the changed shapes
  414.     fDrawSelection->SelectContent(ev, fChangedContent);
  415. }
  416.  
  417. //----------------------------------------------------------------------------------------
  418. //    CChangeShapeCommand::IsOKtoEdit
  419. //----------------------------------------------------------------------------------------
  420.  
  421. FW_Boolean CChangeShapeCommand::IsOKtoEdit(Environment* ev)
  422. {
  423.     FW_Boolean result = FW_CCommand::IsOKtoEdit(ev);
  424.     
  425.     if (result)
  426.         result = fDrawSelection->CanEditSelection(ev, GetContextFrame(ev));
  427.     
  428.     return result;
  429. }
  430.  
  431. //----------------------------------------------------------------------------------------
  432. //    CChangeShapeCommand::PropagateChanges
  433. //----------------------------------------------------------------------------------------
  434.  
  435. void CChangeShapeCommand::PropagateChanges(Environment* ev, ODUpdateID id) 
  436. {
  437.     
  438.     if (id == kODUnknownUpdate)
  439.         id = FW_CSession::UniqueUpdateID(ev);
  440.         
  441.     fDrawSelection->SelectionChanged(ev, id);
  442.     
  443.     FW_CCommand::PropagateChanges(ev, id);
  444. }
  445.  
  446.  
  447.  
  448. //========================================================================================
  449. // CChangeColorCommand
  450. //========================================================================================
  451.  
  452. //----------------------------------------------------------------------------------------
  453. //    CChangeColorCommand constructor
  454. //----------------------------------------------------------------------------------------
  455.  
  456. CChangeColorCommand::CChangeColorCommand(Environment* ev,
  457.                                         ODCommandID commandID,
  458.                                         CDrawPart* part, 
  459.                                         FW_CFrame* frame,
  460.                                         CDrawSelection* selection,
  461.                                         const FW_CColor& newColor)
  462.     : CChangeShapeCommand(ev, commandID, part, frame, selection),
  463.         fNewColor(newColor),
  464.         fOldColors(NULL),
  465.         fIsFill(commandID == cChangeFillColor)
  466. {
  467.     if (fIsFill)
  468.         SetMenuStringsFromResource(ev, kDrawUndoStrings, kUndoFillColorMsg, kRedoFillColorMsg);
  469.     else
  470.         SetMenuStringsFromResource(ev, kDrawUndoStrings, kUndoFrameColorMsg, kRedoFrameColorMsg);
  471.  
  472.     FW_END_CONSTRUCTOR    
  473. }
  474.  
  475. //----------------------------------------------------------------------------------------
  476. //    CChangeColorCommand destructor
  477. //----------------------------------------------------------------------------------------
  478.  
  479. CChangeColorCommand::~CChangeColorCommand()
  480. {
  481.     FW_START_DESTRUCTOR
  482.     FW_CMemoryManager::FreeBlock(fOldColors);
  483. }
  484.  
  485. //----------------------------------------------------------------------------------------
  486. //    CChangeColorCommand::DoChange
  487. //----------------------------------------------------------------------------------------
  488.  
  489. void CChangeColorCommand::DoChange(Environment* ev)            // Override
  490. {
  491.     CAllShapeIterator it(fChangedContent);
  492.     for (CBaseShape* shape = it.First(); it.IsNotComplete(); shape = it.Next())
  493.     {
  494.         if (fIsFill)
  495.             shape->ChangeFillColor(ev, fNewColor);
  496.         else
  497.             shape->ChangeFrameColor(ev, fNewColor);
  498.     }
  499. }
  500.  
  501. //----------------------------------------------------------------------------------------
  502. //    CChangeColorCommand::UndoShape
  503. //----------------------------------------------------------------------------------------
  504.  
  505. void CChangeColorCommand::UndoShape(Environment* ev, CBaseShape* shape, unsigned long index)    // Override
  506. {
  507.     if (fIsFill)
  508.         shape->ChangeFillColor(ev, fOldColors[index]);
  509.     else
  510.         shape->ChangeFrameColor(ev, fOldColors[index]);        
  511. }
  512.  
  513. //----------------------------------------------------------------------------------------
  514. //    CChangeColorCommand::SaveUndoState
  515. //----------------------------------------------------------------------------------------
  516.  
  517. void CChangeColorCommand::SaveUndoState(Environment* ev)    // Override
  518. {
  519. FW_UNUSED(ev);
  520.     CAllShapeIterator it(fChangedContent);
  521.  
  522.     // Create array to hold colors
  523.     unsigned long shapeCount = it.CountShapes();    // count shapes, including grouped ones
  524.     fOldColors = (FW_CColor*)FW_CMemoryManager::AllocateBlock(sizeof(FW_CColor) * shapeCount);
  525.  
  526.     // Save shapes' colors
  527.     FW_CColor color;
  528.     short index = 0;
  529.     for (CBaseShape* shape = it.First(); it.IsNotComplete(); shape = it.Next())
  530.     {
  531.         shape->GetColor(fIsFill, color);
  532.         fOldColors[index] = color;
  533.         index++;
  534.     }    
  535. }
  536.  
  537. //========================================================================================
  538. // class CChangePatternCommand
  539. //========================================================================================
  540.  
  541. //----------------------------------------------------------------------------------------
  542. //    CChangePatternCommand constructor
  543. //----------------------------------------------------------------------------------------
  544.  
  545. CChangePatternCommand::CChangePatternCommand(Environment* ev,
  546.                                             ODCommandID commandID,
  547.                                             CDrawPart* part,
  548.                                             FW_CFrame* frame,
  549.                                             CDrawSelection* selection,
  550.                                             const FW_CPattern& newPattern)
  551.     : CChangeShapeCommand(ev, commandID, part, frame, selection),
  552.         fNewPattern(newPattern),
  553.         fOldPatterns(NULL),
  554.         fCount(0),
  555.         fIsFill(commandID == cChangeFillPattern)
  556. {
  557.     if (fIsFill)
  558.         SetMenuStringsFromResource(ev, kDrawUndoStrings, kUndoFillPatternMsg, kRedoFillPatternMsg);
  559.     else
  560.         SetMenuStringsFromResource(ev, kDrawUndoStrings, kUndoFramePatternMsg, kRedoFramePatternMsg);
  561.     
  562.     FW_END_CONSTRUCTOR    
  563. }
  564.  
  565. //----------------------------------------------------------------------------------------
  566. //    CChangePatternCommand destructor
  567. //----------------------------------------------------------------------------------------
  568.  
  569. CChangePatternCommand::~CChangePatternCommand()
  570. {
  571.     FW_START_DESTRUCTOR
  572.     
  573.     if (fOldPatterns)
  574.     {
  575.         for (unsigned short i = 0; i < fCount; i++)
  576.             delete fOldPatterns[i];
  577.         FW_CMemoryManager::FreeBlock(fOldPatterns);
  578.     }
  579. }
  580.  
  581. //----------------------------------------------------------------------------------------
  582. //    CChangePatternCommand::DoChange
  583. //----------------------------------------------------------------------------------------
  584.  
  585. void CChangePatternCommand::DoChange(Environment* ev)    // Override
  586. {
  587.     CAllShapeIterator it(fChangedContent);
  588.     for (CBaseShape* shape = it.First(); it.IsNotComplete(); shape = it.Next())
  589.     {
  590.         if (fIsFill)
  591.             shape->ChangeFillPattern(ev, fNewPattern);
  592.         else 
  593.             shape->ChangeFramePattern(ev, fNewPattern);
  594.     }
  595. }
  596.  
  597. //----------------------------------------------------------------------------------------
  598. //    CChangePatternCommand::UndoShape
  599. //----------------------------------------------------------------------------------------
  600.  
  601. void CChangePatternCommand::UndoShape(Environment* ev, CBaseShape* shape, unsigned long index)    // Override
  602. {
  603.     if (fIsFill)
  604.         shape->ChangeFillPattern(ev, *(fOldPatterns[index]));
  605.     else
  606.         shape->ChangeFramePattern(ev, *(fOldPatterns[index]));
  607. }
  608.  
  609. //----------------------------------------------------------------------------------------
  610. //    CChangePatternCommand::SaveUndoState
  611. //----------------------------------------------------------------------------------------
  612.  
  613. void CChangePatternCommand::SaveUndoState(Environment* ev)    // Override
  614. {
  615. FW_UNUSED(ev);
  616.     CAllShapeIterator it(fChangedContent);
  617.  
  618.     // Create array to hold patterns
  619.     unsigned long shapeCount = it.CountShapes();    // count shapes, including grouped ones
  620.     fOldPatterns = (FW_CPattern**)FW_CMemoryManager::AllocateBlock(sizeof(FW_CPattern*) * shapeCount);
  621. //    fOldPatterns = new FW_CPattern*[shapeCount];
  622.  
  623.     // Save shapes' patterns
  624.     for (CBaseShape* shape = it.First(); it.IsNotComplete(); shape = it.Next())
  625.     {
  626.         fOldPatterns[fCount] = FW_NEW(FW_CPattern, (shape->GetPattern(fIsFill)));
  627.         fCount++;
  628.     }    
  629. }
  630.  
  631. //========================================================================================
  632. // class CChangeRenderVerbCommand
  633. //========================================================================================
  634.  
  635. //----------------------------------------------------------------------------------------
  636. //    CChangeRenderVerbCommand constructor
  637. //----------------------------------------------------------------------------------------
  638.  
  639. CChangeRenderVerbCommand::CChangeRenderVerbCommand(Environment* ev,
  640.                                                     CDrawPart* part, 
  641.                                                     FW_CFrame* frame,
  642.                                                    CDrawSelection* selection,
  643.                                                    unsigned short newRenderVerb)
  644.     : CChangeShapeCommand(ev, cChangeRenderVerb, part, frame, selection),
  645.         fNewRenderVerb(newRenderVerb),
  646.         fOldRenderVerbs(NULL)
  647. {
  648.     SetMenuStringsFromResource(ev, kDrawUndoStrings, kUndoRenderVerbMsg, kRedoRenderVerbMsg);
  649.     FW_END_CONSTRUCTOR    
  650. }
  651.  
  652. //----------------------------------------------------------------------------------------
  653. //    CChangeRenderVerbCommand destructor
  654. //----------------------------------------------------------------------------------------
  655.  
  656. CChangeRenderVerbCommand::~CChangeRenderVerbCommand()
  657. {
  658.     FW_START_DESTRUCTOR
  659.     delete [] fOldRenderVerbs;
  660. }
  661.  
  662. //----------------------------------------------------------------------------------------
  663. //    CChangeRenderVerbCommand::DoChange
  664. //----------------------------------------------------------------------------------------
  665.  
  666. void CChangeRenderVerbCommand::DoChange(Environment* ev)    // Override
  667. {
  668.     CAllShapeIterator it(fChangedContent);
  669.     for (CBaseShape* shape = it.First(); it.IsNotComplete(); shape = it.Next())
  670.     {
  671.         shape->ChangeRenderVerb(ev, fNewRenderVerb);
  672.     }
  673. }
  674.  
  675. //----------------------------------------------------------------------------------------
  676. //    CChangeRenderVerbCommand::UndoShape
  677. //----------------------------------------------------------------------------------------
  678.  
  679. void CChangeRenderVerbCommand::UndoShape(Environment* ev, CBaseShape* shape, unsigned long index)    // Override
  680. {
  681.     shape->ChangeRenderVerb(ev, fOldRenderVerbs[index]);
  682. }
  683.  
  684. //----------------------------------------------------------------------------------------
  685. //    CChangeRenderVerbCommand::SaveUndoState
  686. //----------------------------------------------------------------------------------------
  687.  
  688. void CChangeRenderVerbCommand::SaveUndoState(Environment* ev)    // Override
  689. {
  690. FW_UNUSED(ev);
  691.     CAllShapeIterator it(fChangedContent);
  692.  
  693.     // Create array to hold render verbs
  694.     unsigned long shapeCount = it.CountShapes();    // count shapes, including grouped ones
  695.     fOldRenderVerbs = new unsigned short[shapeCount];
  696.  
  697.     // Finally, save shapes' render verbs
  698.     unsigned short verb;
  699.     short index = 0;
  700.     for (CBaseShape* shape = it.First(); it.IsNotComplete(); shape = it.Next())
  701.     {
  702.         verb = shape->GetRenderVerb();
  703.         fOldRenderVerbs[index] = verb;
  704.     }    
  705. }
  706.  
  707. //========================================================================================
  708. // class CChangePenSizeCommand
  709. //========================================================================================
  710.  
  711. //----------------------------------------------------------------------------------------
  712. //    CChangePenSizeCommand constructor
  713. //----------------------------------------------------------------------------------------
  714.  
  715. CChangePenSizeCommand::CChangePenSizeCommand(Environment* ev,
  716.                                              CDrawPart* part, 
  717.                                              FW_CFrame* frame,
  718.                                              CDrawSelection* selection,
  719.                                              FW_Fixed newPenSize)
  720.     : CChangeShapeCommand(ev, cChangePenSize, part, frame, selection),
  721.         fNewPenSize(newPenSize),
  722.         fOldPenSizes(NULL)
  723. {
  724.     SetMenuStringsFromResource(ev, kDrawUndoStrings, kUndoPenSizeMsg, kRedoPenSizeMsg);
  725.     FW_END_CONSTRUCTOR    
  726. }
  727.  
  728. //----------------------------------------------------------------------------------------
  729. //    CChangePenSizeCommand destructor
  730. //----------------------------------------------------------------------------------------
  731.  
  732. CChangePenSizeCommand::~CChangePenSizeCommand()
  733. {
  734.     FW_START_DESTRUCTOR
  735.     delete [] fOldPenSizes;
  736. }
  737.  
  738. //----------------------------------------------------------------------------------------
  739. //    CChangePenSizeCommand::DoChange
  740. //----------------------------------------------------------------------------------------
  741.  
  742. void CChangePenSizeCommand::DoChange(Environment* ev)    // Override
  743. {
  744.     CAllShapeIterator it(fChangedContent);
  745.     for (CBaseShape* shape = it.First(); it.IsNotComplete(); shape = it.Next())
  746.     {
  747.         shape->ChangePenSize(ev, fNewPenSize);
  748.     }
  749. }
  750.  
  751. //----------------------------------------------------------------------------------------
  752. //    CChangePenSizeCommand::UndoShape
  753. //----------------------------------------------------------------------------------------
  754.  
  755. void CChangePenSizeCommand::UndoShape(Environment* ev, CBaseShape* shape, unsigned long index)    // Override
  756. {
  757.     shape->ChangePenSize(ev, fOldPenSizes[index]);
  758. }
  759.  
  760. //----------------------------------------------------------------------------------------
  761. //    CChangePenSizeCommand::SaveUndoState
  762. //----------------------------------------------------------------------------------------
  763.  
  764. void CChangePenSizeCommand::SaveUndoState(Environment* ev)    // Override
  765. {
  766. FW_UNUSED(ev);
  767.     CAllShapeIterator it(fChangedContent);
  768.  
  769.     // Create array to hold pen sizes
  770.     unsigned long shapeCount = it.CountShapes();    // count shapes, including grouped ones
  771.     fOldPenSizes = new FW_Fixed[shapeCount];
  772.  
  773.     // Finally, save shapes' pen sizes
  774.     FW_Fixed penSize;
  775.     short index = 0;
  776.     for (CBaseShape* shape = it.First(); it.IsNotComplete(); shape = it.Next())
  777.     {
  778.         penSize = shape->GetPenSize();
  779.         fOldPenSizes[index] = penSize;
  780.     }    
  781. }
  782.